/**
 * axiosInstance的请求实例                            
 */
import axios from "axios";
import router from "../router";
import {mainStore} from "../store"

const axiosInstance = axios.create({
    baseURL: baseURL,
    timeout: 5000
});

//设置请求拦截，在每次请求之前都携带之前登录的token
axiosInstance.interceptors.request.use(config=>{
    const store=mainStore();
    config.headers["softeem_ele_admin_token"]=store.token;
    return config
})

// 设置响应拦截
axiosInstance.interceptors.response.use(resp => {
    if (resp.data.status === "success") {
        return Promise.resolve(resp.data.data);
    } else {
        console.log("请求是对的但是服务器错了");
        return Promise.reject(resp.data)
    }
}, error => {
    console.log("服务器错误",error);
    if(error.response.status===403){
        router.replace({
            name:"Login"
        })
    }

    return Promise.reject(error);
})



export default axiosInstance;